<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-09-29 09:32
 *
 * Version: 2.0
 */

namespace App\Modules\Order\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class findServiceTypeOrderListCriteria extends BaseCriterias
{
	private $params;

	public function __construct($dateList, $storeId, $type)
	{
		$this->params = [
			'date'     => $dateList,
			'store_id' => $storeId,
			'type'     => $type
		];
	}


	public function apply($model, RepositoryInterface $repository)
	{
		$type = $this->params['type'];
		$storeId = $this->params['store_id'];
		$dateList = $this->params['date'];

		return $model
			->select(['order.id','order_item.service_name','order.finish_time','order.real_price','order.profit','user.nick','picture.image','store_service.type'])
			->leftJoin('store_service','store_service.id','order_item.service_id')
			->leftJoin('order', 'order.id', 'order_item.order_id')
			->leftJoin('user','user.id','order.barber_id')
			->leftJoin('picture','picture.id','user.portrait')
			->whereIn('type', $type)
			->where(['order.store_id' => $storeId, 'order.status' => 2])
			->whereRaw('FROM_UNIXTIME(finish_time,\'%Y-%m-%d\') >= "' . $dateList['end_date'] . '" and FROM_UNIXTIME(finish_time,\'%Y-%m-%d\') <= "' . $dateList['start_date'] . '"');

	}
}